<?php
class faq{
	//faq selcction function
	function selectFaq()
	{
		global $con;
		$sql="select * from tbl_faq";
		$res = mysqli_query($con,$sql);
		return $res;
	}/// EOF
	
	
	//function for adding FAQ
	
	function insertFaq($question,$answer,$status)
	{
		global $con;
		$sql=sprintf("INSERT INTO tbl_faq SET faq_question='%s',
							faq_answer='%s',
							faq_status='%s'",
							mysqli_escape_string($con,$question),
							mysqli_escape_string($con,$answer),
							mysqli_escape_string($con,$status));
		$res = mysqli_query($con,$sql);
		//var_dump($res);die;
		return $res;
	}/// EOF
	
	//function for updating faq
	function updateFaq($id,$question,$answer,$status){
		
		global $con;
		echo $sql=sprintf("update tbl_faq SET faq_question='%s',
							faq_answer='%s',
							faq_status='%s' where faq_id=%d",
							mysqli_escape_string($con,$question),
							mysqli_escape_string($con,$answer),
							mysqli_escape_string($con,$status),
							mysqli_escape_string($con,$id));
		$res = mysqli_query($con,$sql);
		if(!$res){
			die("Sql error " . mysqli_error($con));
		}
		return $res;	
	
	}
	//function for deleting faq
	function deleteFaq($id)
	{
		global $con;
		$sql="DELETE FROM tbl_faq WHERE faq_id='$id' ";
		mysqli_query($con,$sql);
	}
	//function updating status
	function updateStatus($id,$status){
		global $con;
		$sql="update tbl_faq set faq_status='$status' where faq_id='$id'";
		$res=mysqli_query($con,$sql);
		return $res;
		
	}
	
	//function selecting ststus set faqs
	function selectSetFaq(){
		global $con;
		$sql="select * from tbl_faq where faq_status='1'";
		$res = mysqli_query($con,$sql);
		return $res;
	}
	
	//function selecting item by id
	function getFaqById($id){
		global $con;
		$sql="select * from tbl_faq where faq_id='$id'";
		$res = mysqli_query($con,$sql);
		return $res;
	}
	
}	


$objFaq =new faq();
?>
